package website.lucaswork.survey.core.converters;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;
import website.lucaswork.survey.core.utils.DefaultValues;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

@Component
public class LocalDateTimeToStringConverter implements Converter<LocalDateTime, String> {
    @Autowired
    DefaultValues defaultValues;
    @Override
    public String convert(LocalDateTime source) {
        if (source == null) {
            return "";
        }
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(defaultValues.getDefaultDatetimeFormat());
        return source.format(formatter);
    }
}
